package com.ofsoft.weixin.mp.api;

import com.ofsoft.weixin.mp.AppConfig;

/**
 * accessToken处理
 * 
 * @author OF
 * @date 2017年10月16日
 */
public class AccessTokenApi extends ApiBase {

	/**
	 * 获取普通accessToken<br>
	 * {"access_token":"ACCESS_TOKEN","expires_in":7200}
	 * 
	 * @return json
	 */
	public static ApiResponse getAccessTokenApi() {
		String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&"
				+ "appid="
				+ AppConfig.getAppId()
				+ "&secret="
				+ AppConfig.getAppSecret();
		return sendGet(url);
	}

	/**
	 * 网页授权获取accessToken
	 * 
	 * @param code
	 *            微信服务返回
	 * @return
	 */
	public static ApiResponse getOauthToken(String code) {
		String url = "https://api.weixin.qq.com/sns/oauth2/access_token?"
				+ "appid=" + AppConfig.getAppId() + "&secret="
				+ AppConfig.getAppSecret() + "&code=" + code
				+ "&grant_type=authorization_code";
		return sendGet(url);
	}

	/**
	 * 刷新页面访问 token
	 * 
	 * @param refreshToken
	 *            刷新token
	 * @return
	 */
	public static ApiResponse getRefreshOauthToken(String refreshToken) {
		String url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?"
				+ "appid=" + AppConfig.getAppId()
				+ "&grant_type=refresh_token&" + "refresh_token="
				+ refreshToken;
		return sendGet(url);
	}

}
